package org.wesc.boot.webapi.api.common;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wesc.boot.service.common.CommonService;
import org.wesc.boot.service.exception.ServiceException;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @author Wesley
 * @date 2021/5/21
 */
@Api(tags={"通用接口"})
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/common")
public class CommonApi {

    private final CommonService commonService;

    @ApiOperation(value = "文件下载")
    @PostMapping("/download")
    public void download(@Valid String filename, HttpServletResponse response) throws ServiceException {
        this.commonService.downloadFile(filename, response);
    }
}
